using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Dynamic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.CompilerServices;
using System.Threading;
using ns19;
using ns20;

namespace Newtonsoft.Json.Linq
{
	public class JObject : JContainer, IDictionary<string, JToken>, ICollection<KeyValuePair<string, JToken>>, IEnumerable<KeyValuePair<string, JToken>>, IEnumerable, INotifyPropertyChanged, ICustomTypeDescriptor, INotifyPropertyChanging
	{
		private class Class88 : Class86<JObject>
		{
			[CompilerGenerated]
			private static Func<JProperty, string> func_0;

			public override bool ns20_002EClass86_003CNewtonsoft_002EJson_002ELinq_002EJObject_003E_002E_200C_200E_200F_200D_202E_206F_202A_206E_200F_206C_202C_202A_206E_206D_200E_200D_200F_206B_206F_206F_206D_200E_206B_202E_206F_206F_202C_200B_200C_202C_206A_206A_202E_206B_202B_202A_200E_202B_206D_200E_202E(JObject jobject_0, GetMemberBinder getMemberBinder_0, out object object_0)
			{
				object_0 = jobject_0[getMemberBinder_0.Name];
				return true;
			}

			public override bool ns20_002EClass86_003CNewtonsoft_002EJson_002ELinq_002EJObject_003E_002E_202D_206F_206D_202B_206C_206A_206F_200D_202B_206D_206D_202B_206C_202A_206A_206C_202D_206F_202C_200E_200E_200F_200C_200F_206C_202A_200C_206C_202C_206A_206C_200D_206C_206F_202A_202A_202A_206D_206D_200F_202E(JObject jobject_0, SetMemberBinder setMemberBinder_0, object object_0)
			{
				JToken jToken = object_0 as JToken;
				if (jToken == null)
				{
					jToken = new JValue(object_0);
				}
				jobject_0[setMemberBinder_0.Name] = jToken;
				return true;
			}

			public override IEnumerable<string> ns20_002EClass86_003CNewtonsoft_002EJson_002ELinq_002EJObject_003E_002E_202D_206C_200E_202A_202E_206E_206F_202C_202B_200C_200B_206D_202E_206F_206F_206B_206F_200B_206A_206B_202B_202E_206C_202B_202D_206C_206B_206D_200E_202D_202D_206F_202B_202D_200B_202D_200B_206D_200E_200E_202E(JObject jobject_0)
			{
				return from jproperty_0 in jobject_0.Properties()
					select jproperty_0.Name;
			}

			[CompilerGenerated]
			private static string smethod_0(JProperty jproperty_0)
			{
				return jproperty_0.Name;
			}
		}

		private readonly Class80 class80_0 = new Class80();

		private PropertyChangedEventHandler propertyChangedEventHandler_0;

		private PropertyChangingEventHandler propertyChangingEventHandler_0;

		[CompilerGenerated]
		private static Func<JProperty, JToken> func_0;

		protected override IList<JToken> ChildrenTokens => class80_0;

		public override JTokenType Type => JTokenType.Object;

		public override JToken this[object key]
		{
			get
			{
				Class204.smethod_2(key, "o");
				string text = key as string;
				if (text == null)
				{
					throw new ArgumentException("Accessed JObject values with invalid key value: {0}. Object property name expected.".smethod_0(CultureInfo.InvariantCulture, Class194.smethod_2(key)));
				}
				return this[text];
			}
			set
			{
				Class204.smethod_2(key, "o");
				string text = key as string;
				if (text == null)
				{
					throw new ArgumentException("Set JObject values with invalid key value: {0}. Object property name expected.".smethod_0(CultureInfo.InvariantCulture, Class194.smethod_2(key)));
				}
				this[text] = value;
			}
		}

		public JToken this[string propertyName]
		{
			get
			{
				Class204.smethod_2(propertyName, "propertyName");
				return Property(propertyName)?.Value;
			}
			set
			{
				JProperty jProperty = Property(propertyName);
				if (jProperty != null)
				{
					jProperty.Value = value;
					return;
				}
				OnPropertyChanging(propertyName);
				Add(new JProperty(propertyName, value));
				OnPropertyChanged(propertyName);
			}
		}

		ICollection<string> IDictionary<string, JToken>.Keys => class80_0.ICollection_0;

		ICollection<JToken> IDictionary<string, JToken>.Values
		{
			get
			{
				throw new NotImplementedException();
			}
		}

		bool ICollection<KeyValuePair<string, JToken>>.IsReadOnly => false;

		public event PropertyChangedEventHandler PropertyChanged
		{
			add
			{
				PropertyChangedEventHandler propertyChangedEventHandler = propertyChangedEventHandler_0;
				PropertyChangedEventHandler propertyChangedEventHandler2;
				do
				{
					propertyChangedEventHandler2 = propertyChangedEventHandler;
					PropertyChangedEventHandler value2 = (PropertyChangedEventHandler)Delegate.Combine(propertyChangedEventHandler2, value);
					propertyChangedEventHandler = Interlocked.CompareExchange(ref propertyChangedEventHandler_0, value2, propertyChangedEventHandler2);
				}
				while ((object)propertyChangedEventHandler != propertyChangedEventHandler2);
			}
			remove
			{
				PropertyChangedEventHandler propertyChangedEventHandler = propertyChangedEventHandler_0;
				PropertyChangedEventHandler propertyChangedEventHandler2;
				do
				{
					propertyChangedEventHandler2 = propertyChangedEventHandler;
					PropertyChangedEventHandler value2 = (PropertyChangedEventHandler)Delegate.Remove(propertyChangedEventHandler2, value);
					propertyChangedEventHandler = Interlocked.CompareExchange(ref propertyChangedEventHandler_0, value2, propertyChangedEventHandler2);
				}
				while ((object)propertyChangedEventHandler != propertyChangedEventHandler2);
			}
		}

		public event PropertyChangingEventHandler PropertyChanging
		{
			add
			{
				PropertyChangingEventHandler propertyChangingEventHandler = propertyChangingEventHandler_0;
				PropertyChangingEventHandler propertyChangingEventHandler2;
				do
				{
					propertyChangingEventHandler2 = propertyChangingEventHandler;
					PropertyChangingEventHandler value2 = (PropertyChangingEventHandler)Delegate.Combine(propertyChangingEventHandler2, value);
					propertyChangingEventHandler = Interlocked.CompareExchange(ref propertyChangingEventHandler_0, value2, propertyChangingEventHandler2);
				}
				while ((object)propertyChangingEventHandler != propertyChangingEventHandler2);
			}
			remove
			{
				PropertyChangingEventHandler propertyChangingEventHandler = propertyChangingEventHandler_0;
				PropertyChangingEventHandler propertyChangingEventHandler2;
				do
				{
					propertyChangingEventHandler2 = propertyChangingEventHandler;
					PropertyChangingEventHandler value2 = (PropertyChangingEventHandler)Delegate.Remove(propertyChangingEventHandler2, value);
					propertyChangingEventHandler = Interlocked.CompareExchange(ref propertyChangingEventHandler_0, value2, propertyChangingEventHandler2);
				}
				while ((object)propertyChangingEventHandler != propertyChangingEventHandler2);
			}
		}

		public JObject()
		{
		}

		public JObject(JObject other)
			: base(other)
		{
		}

		public JObject(params object[] content)
			: this((object)content)
		{
		}

		public JObject(object content)
		{
			Add(content);
		}

		internal override bool Newtonsoft_002EJson_002ELinq_002EJToken_002E_206F_200C_206F_206F_206B_200E_206C_206B_200C_200D_202E_200E_200E_200D_202C_200D_200C_206B_200F_202D_202E_200F_200C_202D_206B_200D_206B_206E_202E_206E_202B_206D_206E_206F_202C_202E_200D_200C_200D_200F_202E(JToken jtoken_2)
		{
			JObject jObject = jtoken_2 as JObject;
			if (jObject == null)
			{
				return false;
			}
			return class80_0.method_9(jObject.class80_0);
		}

		 internal override void Newtonsoft_002EJson_002ELinq_002EJContainer_002E_206F_206C_206F_206D_202A_200D_202E_202E_200B_202D_202C_206D_200F_202A_200D_202C_202B_202A_206D_202D_202A_200D_206A_200E_206C_206C_200C_202B_206D_200E_206E_200B_200B_206A_202E_200F_206F_206F_202E_206C_202E(int int_0, JToken jtoken_2, bool bool_1)
		{
			if (jtoken_2 == null || jtoken_2.Type != JTokenType.Comment)
			{
				base.Newtonsoft_002EJson_002ELinq_002EJContainer_002E_206F_206C_206F_206D_202A_200D_202E_202E_200B_202D_202C_206D_200F_202A_200D_202C_202B_202A_206D_202D_202A_200D_206A_200E_206C_206C_200C_202B_206D_200E_206E_200B_200B_206A_202E_200F_206F_206F_202E_206C_202E(int_0, jtoken_2, bool_1);
			}
		}

		internal override void Newtonsoft_002EJson_002ELinq_002EJContainer_002E_200C_200E_206E_206C_200B_202E_202D_202D_200F_200B_200D_200F_206A_200B_206D_202B_200F_206C_200E_206F_202C_206E_202A_200C_200D_206C_202B_200C_202B_202D_200C_200D_200E_202E_206F_206B_200D_202B_202C_206F_202E(JToken jtoken_2, JToken jtoken_3)
		{
			Class204.smethod_2(jtoken_2, "o");
			if (jtoken_2.Type != JTokenType.Property)
			{
				throw new ArgumentException("Can not add {0} to {1}.".smethod_1(CultureInfo.InvariantCulture, jtoken_2.GetType(), GetType()));
			}
			JProperty jProperty = (JProperty)jtoken_2;
			if (jtoken_3 != null)
			{
				JProperty jProperty2 = (JProperty)jtoken_3;
				if (jProperty.Name == jProperty2.Name)
				{
					return;
				}
			}
			if (class80_0.method_8(jProperty.Name, out jtoken_3))
			{
				throw new ArgumentException("Can not add property {0} to {1}. Property with the same name already exists on object.".smethod_1(CultureInfo.InvariantCulture, jProperty.Name, GetType()));
			}
		}

		internal void method_14(JProperty jproperty_0)
		{
			OnPropertyChanged(jproperty_0.Name);
			if (listChangedEventHandler_0 != null)
			{
				OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, method_6(jproperty_0)));
			}
			if (notifyCollectionChangedEventHandler_0 != null)
			{
				OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, jproperty_0, jproperty_0, method_6(jproperty_0)));
			}
		}

		internal void method_15(JProperty jproperty_0)
		{
			OnPropertyChanging(jproperty_0.Name);
		}

		internal override JToken Newtonsoft_002EJson_002ELinq_002EJToken_002E_206F_206A_202E_200B_200D_206A_200C_200E_206A_202D_200E_206E_206F_200B_206C_200F_200C_200C_202A_206B_200C_202D_200B_202B_202A_202D_202B_206A_206F_206F_202D_200C_206F_202E_206B_200D_206C_202D_202E_200E_202E()
		{
			return new JObject(this);
		}

		public IEnumerable<JProperty> Properties()
		{
			return class80_0.Cast<JProperty>();
		}

		public JProperty Property(string name)
		{
			if (name == null)
			{
				return null;
			}
			class80_0.method_8(name, out var jToken);
			return (JProperty)jToken;
		}

		public JEnumerable<JToken> PropertyValues()
		{
			return new JEnumerable<JToken>(from jproperty_0 in Properties()
				select jproperty_0.Value);
		}

		public new static JObject Load(JsonReader reader)
		{
			Class204.smethod_2(reader, "reader");
			if (reader.JsonToken_0 == JsonToken.None && !reader.Read())
			{
				throw JsonReaderException.smethod_1(reader, "Error reading JObject from JsonReader.");
			}
			while (reader.JsonToken_0 == JsonToken.Comment)
			{
				reader.Read();
			}
			if (reader.JsonToken_0 != JsonToken.StartObject)
			{
				throw JsonReaderException.smethod_1(reader, "Error reading JObject from JsonReader. Current JsonReader item is not an object: {0}".smethod_0(CultureInfo.InvariantCulture, reader.JsonToken_0));
			}
			JObject jObject = new JObject();
			jObject.method_0(reader as IJsonLineInfo);
			jObject.method_10(reader);
			return jObject;
		}

		public new static JObject Parse(string json)
		{
			JsonReader jsonReader = new JsonTextReader(new StringReader(json));
			JObject result = Load(jsonReader);
			if (jsonReader.Read() && jsonReader.JsonToken_0 != JsonToken.Comment)
			{
				throw JsonReaderException.smethod_1(jsonReader, "Additional text found in JSON string after parsing content.");
			}
			return result;
		}

		public new static JObject FromObject(object o)
		{
			return FromObject(o, JsonSerializer.CreateDefault());
		}

		public new static JObject FromObject(object o, JsonSerializer jsonSerializer)
		{
			JToken jToken = JToken.smethod_5(o, jsonSerializer);
			if (jToken != null && jToken.Type != JTokenType.Object)
			{
				throw new ArgumentException("Object serialized to {0}. JObject instance expected.".smethod_0(CultureInfo.InvariantCulture, jToken.Type));
			}
			return (JObject)jToken;
		}

		public override void WriteTo(JsonWriter writer, params JsonConverter[] converters)
		{
			writer.WriteStartObject();
			for (int i = 0; i < class80_0.Count; i++)
			{
				class80_0[i].WriteTo(writer, converters);
			}
			writer.WriteEndObject();
		}

		public JToken GetValue(string propertyName)
		{
			return GetValue(propertyName, StringComparison.Ordinal);
		}

		public JToken GetValue(string propertyName, StringComparison comparison)
		{
			if (propertyName == null)
			{
				return null;
			}
			JProperty jProperty = Property(propertyName);
			if (jProperty != null)
			{
				return jProperty.Value;
			}
			if (comparison != StringComparison.Ordinal)
			{
				foreach (JProperty item in class80_0)
				{
					if (string.Equals(item.Name, propertyName, comparison))
					{
						return item.Value;
					}
				}
			}
			return null;
		}

		public bool TryGetValue(string propertyName, StringComparison comparison, out JToken value)
		{
			value = GetValue(propertyName, comparison);
			return value != null;
		}

		public void Add(string propertyName, JToken value)
		{
			Add(new JProperty(propertyName, value));
		}

		bool IDictionary<string, JToken>.ContainsKey(string key)
		{
			return class80_0.method_2(key);
		}

		public bool Remove(string propertyName)
		{
			JProperty jProperty = Property(propertyName);
			if (jProperty == null)
			{
				return false;
			}
			jProperty.Remove();
			return true;
		}

		public bool TryGetValue(string propertyName, out JToken value)
		{
			JProperty jProperty = Property(propertyName);
			if (jProperty == null)
			{
				value = null;
				return false;
			}
			value = jProperty.Value;
			return true;
		}

		void ICollection<KeyValuePair<string, JToken>>.Add(KeyValuePair<string, JToken> item)
		{
			Add(new JProperty(item.Key, item.Value));
		}

		void ICollection<KeyValuePair<string, JToken>>.Clear()
		{
			RemoveAll();
		}

		bool ICollection<KeyValuePair<string, JToken>>.Contains(KeyValuePair<string, JToken> item)
		{
			JProperty jProperty = Property(item.Key);
			if (jProperty == null)
			{
				return false;
			}
			return jProperty.Value == item.Value;
		}

		void ICollection<KeyValuePair<string, JToken>>.CopyTo(KeyValuePair<string, JToken>[] array, int arrayIndex)
		{
			if (array == null)
			{
				throw new ArgumentNullException("array");
			}
			if (arrayIndex < 0)
			{
				throw new ArgumentOutOfRangeException("arrayIndex", "arrayIndex is less than 0.");
			}
			if (arrayIndex >= array.Length && arrayIndex != 0)
			{
				throw new ArgumentException("arrayIndex is equal to or greater than the length of array.");
			}
			if (base.Count > array.Length - arrayIndex)
			{
				throw new ArgumentException("The number of elements in the source JObject is greater than the available space from arrayIndex to the end of the destination array.");
			}
			int num = 0;
			foreach (JProperty item in class80_0)
			{
				ref KeyValuePair<string, JToken> reference = ref array[arrayIndex + num];
				reference = new KeyValuePair<string, JToken>(item.Name, item.Value);
				num++;
			}
		}

		bool ICollection<KeyValuePair<string, JToken>>.Remove(KeyValuePair<string, JToken> item)
		{
			if (!((ICollection<KeyValuePair<string, JToken>>)this).Contains(item))
			{
				return false;
			}
			((IDictionary<string, JToken>)this).Remove(item.Key);
			return true;
		}

		internal override int Newtonsoft_002EJson_002ELinq_002EJToken_002E_200C_202A_206D_200B_206C_206F_202A_200F_200E_206E_200D_202D_200B_200D_206E_202D_206E_200D_202E_206B_206F_206F_202B_206D_206D_202E_206C_200F_202D_202A_206B_206B_200D_202A_200C_202D_200F_202A_206F_200F_202E()
		{
			return method_12();
		}

		public IEnumerator<KeyValuePair<string, JToken>> GetEnumerator()
		{
			foreach (JProperty item in class80_0)
			{
				yield return new KeyValuePair<string, JToken>(item.Name, item.Value);
			}
		}

		protected virtual void OnPropertyChanged(string propertyName)
		{
			if (propertyChangedEventHandler_0 != null)
			{
				propertyChangedEventHandler_0(this, new PropertyChangedEventArgs(propertyName));
			}
		}

		protected virtual void OnPropertyChanging(string propertyName)
		{
			if (propertyChangingEventHandler_0 != null)
			{
				propertyChangingEventHandler_0(this, new PropertyChangingEventArgs(propertyName));
			}
		}

		PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties()
		{
			return ((ICustomTypeDescriptor)this).GetProperties((Attribute[])null);
		}

		private static Type smethod_7(JToken jtoken_2)
		{
			if (jtoken_2 is JValue)
			{
				JValue jValue = (JValue)jtoken_2;
				if (jValue.Value == null)
				{
					return typeof(object);
				}
				return jValue.Value.GetType();
			}
			return jtoken_2.GetType();
		}

		PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes)
		{
			PropertyDescriptorCollection propertyDescriptorCollection = new PropertyDescriptorCollection(null);
			using IEnumerator<KeyValuePair<string, JToken>> enumerator = GetEnumerator();
			while (enumerator.MoveNext())
			{
				KeyValuePair<string, JToken> current = enumerator.Current;
				propertyDescriptorCollection.Add(new JPropertyDescriptor(current.Key, smethod_7(current.Value)));
			}
			return propertyDescriptorCollection;
		}

		AttributeCollection ICustomTypeDescriptor.GetAttributes()
		{
			return AttributeCollection.Empty;
		}

		string ICustomTypeDescriptor.GetClassName()
		{
			return null;
		}

		string ICustomTypeDescriptor.GetComponentName()
		{
			return null;
		}

		TypeConverter ICustomTypeDescriptor.GetConverter()
		{
			return new TypeConverter();
		}

		EventDescriptor ICustomTypeDescriptor.GetDefaultEvent()
		{
			return null;
		}

		PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty()
		{
			return null;
		}

		object ICustomTypeDescriptor.GetEditor(Type editorBaseType)
		{
			return null;
		}

		EventDescriptorCollection ICustomTypeDescriptor.GetEvents(Attribute[] attributes)
		{
			return EventDescriptorCollection.Empty;
		}

		EventDescriptorCollection ICustomTypeDescriptor.GetEvents()
		{
			return EventDescriptorCollection.Empty;
		}

		object ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor pd)
		{
			return null;
		}

		protected override DynamicMetaObject GetMetaObject(Expression parameter)
		{
			return new Class144<JObject>(parameter, this, new Class88(), dontFallbackFirst: true);
		}

		[CompilerGenerated]
		private static JToken smethod_8(JProperty jproperty_0)
		{
			return jproperty_0.Value;
		}
	}
}
